import { createRouter, createWebHashHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/login',
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/LoginView.vue'),
    },
    {
      path: '/home',
      name: 'home',
      component: HomeView,
      redirect: '/input',
      children: [
        {
          path: '/input',
          name: 'input',
          component: () => import('../views/InputView.vue'),
        },
        {
          path: '/chart',
          name: 'chart',
          component: () => import('../views/ChartView.vue'),
        },
        {
          path: '/info',
          name: 'info',
          component: () => import('../views/InfoView.vue'),
        },
      ],
    },
    {
      path: '/manage',
      name: 'manage',
      component: () => import('../views/ManageView.vue'),
      redirect: '/user',
      children: [
        {
          path: '/user',
          name: 'user',
          component: () => import('../components/User.vue'),
        },
        {
          path: '/barge',
          name: 'barge',
          component: () => import('../components/Barge.vue'),
        },
        {
          path: '/fisher',
          name: 'fisher',
          component: () => import('../components/Fisher.vue'),
        },
      ]
    },
    {
      path: '/report',
      name: 'report',
      component: () => import('../views/ReportView.vue'),
    }
  ]
})

// 前置守卫
// router.beforeEach((to, from, next) => {
//   const isLogin = localStorage.getItem('userInfo') ? true : false
//   let { role } = JSON.parse(localStorage.getItem('userInfo')) || {}
//   if (to.name === 'login') {
//     next()
//   } else {
//     if (isLogin) {
//       if(role=='jh'){
//         next()
//       }else if (role=='jg'){
//         // 不能去到input页面
//         if(to.name=='input'){
//           next({ name: 'info' })
//         }else{
//           next()
//         }
//       }else{
//         next({ name: 'info' })
//       }
//     } else {
//       next({ name: 'login'})
//     }
//   }
// })

export default router
